<?php

if (!defined('BASEPATH'))
    exit('No direct script access allowed');

class evaluasi_model extends CI_Model {

    function __construct() 
	{
        parent::__construct();
        $this->CI = get_instance();
    }

    function insert($data) 
	{
        $this->db->insert('evaluasi', $data);
    }
	
	function update($id, $data) 
	{
        $this->db->where('ID_EVALUASI', $id);
        $this->db->update('evaluasi', $data);
    }	
	
    function delete($id) 
	{
        $this->db->where('ID_EVALUASI', $id);
        $this->db->delete('evaluasi');
    }
	
    //list flexy
    function get_data_evaluasi() 
	{
        //Select table name
        $table_name = "evaluasi";

        //Build contents query
        $this->db->select('*')->from($table_name);
		
        $this->CI->flexigrid->build_query();

        //Get contents
        $return['records'] = $this->db->get();

        //Build count query
        $this->db->select('*')->from($table_name);
		$this->CI->flexigrid->build_query(FALSE);

        $return['record_count'] = $this->db->count_all_results();

        //Return all
        return $return;
    }

    function selectone($id) 
	{
        $this->db->select("*");
        $this->db->from('evaluasi');
        $this->db->where('ID_EVALUASI', $id);
        $query = $this->db->get();
        return $query;
    }
	
	function active_evaluasi() 
	{
		$this->db->select('*');
		$this->db->from('evaluasi');
		$this->db->where('AKTIF = 1');
		return $this->db->get()->result();
	}	
	
	//-----------------Start Update Status Aktif periode-------------------//
	function set_status_nol($data)
	{
		$this->db->where('AKTIF', 1);
		$this->db->update('evaluasi', $data);
	}
	
	function set_status_satu($id, $data)
	{
		$this->db->where('ID_EVALUASI', $id);
		$this->db->update('evaluasi', $data);
	}
	//-----------------End Update Status Aktif periode-------------------//
	
	function get_data_evaluasi_proyek(){
		//Select table name
		$table_name = "evaluasi";
		
		//Build contents query
		$this->db->select('*')->from($table_name);		
		$this->db->join('PROYEK AS P','evaluasi.ID_PROYEK = P.ID_PROYEK','left');
		// $this->db->where('ID_EVALUASI', $id); 
		// $this->db->where('status',  'Luar Biasa');
		$this->CI->flexigrid->build_query();
		
		//Get contents
		$return['records'] = $this->db->get();
		
		//Build count query
		$this->db->select('*')->from($table_name);
		$this->db->join('PROYEK AS P','evaluasi.ID_PROYEK = P.ID_PROYEK','left');
		// $this->db->where('ID_EVALUASI', $id); 
		// $this->db->where('status',  'Luar Biasa');
		$this->CI->flexigrid->build_query(FALSE);
		
		$return['record_count'] = $this->db->count_all_results();
	
		//Return all
		return $return;
	}	
	
	function get_nama_proyek($id_evaluasi) 
	{
		$this->db->select("*");
        $this->db->from('evaluasi');
		$this->db->join('PROYEK AS P','evaluasi.ID_PROYEK = P.ID_PROYEK','left');
		$this->db->where('ID_EVALUASI', $id_evaluasi);        
        $query = $this->db->get();
        return $query;
	}
			
}	

?>